package cn.iocoder.yudao.module.famous.doctor.controller.app.attention;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.famous.doctor.controller.admin.attention.vo.*;
import cn.iocoder.yudao.module.famous.doctor.convert.attention.AttentionConvert;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.attention.AttentionDO;
import cn.iocoder.yudao.module.famous.doctor.service.attention.AttentionService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

@Tag(name = "用户 APP - 我的关注")
@RestController
@RequestMapping("/famous.doctor/attention/app")
@Validated
public class AppAttentionController {

    @Resource
    private AttentionService attentionService;

    @PostMapping("/create")
    @Operation(summary = "创建我的关注")
    public CommonResult<Long> createAttention(@Valid @RequestBody AttentionCreateReqVO createReqVO) {
        return success(attentionService.createAttention(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新我的关注")
    public CommonResult<Boolean> updateAttention(@Valid @RequestBody AttentionUpdateReqVO updateReqVO) {
        attentionService.updateAttention(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除我的关注")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteAttention(@RequestParam("id") Long id) {
        attentionService.deleteAttention(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得我的关注")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AttentionRespVO> getAttention(@RequestParam("id") Long id) {
        AttentionDO attention = attentionService.getAttention(id);
        return success(AttentionConvert.INSTANCE.convert(attention));
    }

    @GetMapping("/list")
    @Operation(summary = "获得我的关注列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<AttentionRespVO>> getAttentionList(@RequestParam("ids") Collection<Long> ids) {
        List<AttentionDO> list = attentionService.getAttentionList(ids);
        return success(AttentionConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/getAttentionMessagePage")
    @Operation(summary = "获得我的关注分页(有关注人信息)")
    public CommonResult<IPage<AttentionPageRespVO>> getAttentionMessagePage(@Valid AttentionPageReqVO pageVO) {
        IPage<AttentionPageRespVO> pageResult = attentionService.getAttentionMessagePage(pageVO);
        return success(pageResult);
    }

}
